using System.Text.RegularExpressions;
using Headspring.Training.IntegrationTests;
using NUnit.Framework;
using WatiN.Core;

namespace Headspring.Training.FullSystemTests
{
	public class BaseTester : DataTestBase
	{
		protected SmartIE _browser;

		[TestFixtureSetUp]
		public void Before_all_specs()
		{
			_browser = new SmartIE("http://localhost:1216");
		}

		[SetUp]
		public override void Setup()
		{
			base.Setup();
			new ZDataLoader().PopulateDatabase();
			_browser.NavigateTo("/login");
		}

		[TestFixtureTearDown]
		public void After_all_specs()
		{
			if (_browser != null)
			{
				_browser.Dispose();
			}
		}

		public void LoginAsJeffrey()
		{
			SelectList userList = _browser.SelectList(new Regex("username"));
			Button submitButton = _browser.Button(Find.By("type", "submit"));

			userList.Select("Jeffrey Palermo");

			submitButton.Click();
		}

		protected void NavigateToOrderEdit(string orderNumber)
		{
			_browser.NavigateTo(string.Format("/workorder/edit?workordernumber={0}",
			                                  orderNumber));
		}
	}
}